package com.zsh.weather.ln.home.ui.search.presenter

import com.yechaoa.yutilskt.LogUtilKt
import com.zsh.weather.ln.base.BasePresenter
import com.zsh.weather.ln.base.OnLoadDataListener
import com.zsh.weather.ln.bean.CityHotList
import com.zsh.weather.ln.bean.CitySearchList
import com.zsh.weather.ln.home.ui.search.contract.SearchConstract
import com.zsh.weather.ln.home.ui.search.model.SearchModel

class SearchPresenter: BasePresenter<SearchConstract.View>(),SearchConstract.Presenter {
    override fun getHotCitys() {
        SearchModel().getHotCitys(object : OnLoadDataListener {
            override fun <T> success(result: T) {
                getView()!!.getHotCitys(result as CityHotList)
            }

            override fun fail(error: String) {
                LogUtilKt.d("请求失败。。。。。。。" + error)
            }
        })
    }

    override fun startSearch(str: String) {
        SearchModel().startSearch(str,object : OnLoadDataListener{
            override fun <T> success(result: T) {
                getView()!!.searchResult(result as CitySearchList)
            }
            override fun fail(error: String) {
                getView()!!.error("未搜索到结果")
            }
        })
    }
}